#coding:utf-8
from django.contrib.auth.backends import ModelBackend

from MSB_ERP.utils.cache_permissions import redis_storage_permissions
from .models import UserModel
class UserLoginAuth(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):
        #实现用户认证
        try:
            user=UserModel.objects.get(username=username)
        except:
            return None
        #判断密码
        if user.check_password(password):
            redis_storage_permissions(user)
            return user #把user对象放到request对象中